package com.atguigu.gulimall.search.thread;

import java.util.concurrent.*;

public class ThreadTest {

    public static ExecutorService service = Executors.newFixedThreadPool(10);
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        System.out.println("start...");
        /**
         * 1.Thread
         *        Thread01 thread01 = new Thread01();
         *        thread01.start();
         * 2.Runnable
         *        Thread thread = new Thread(new Runnable01());
         *        thread.start();
         * 3.Callable + FutureTask
         *        FutureTask<Integer> integerFutureTask = new FutureTask<>(new Callable01());
         *        Thread thread = new Thread(integerFutureTask);
         *        thread.start();
         *        //阻塞方法
         *        System.out.println("返回值：" + integerFutureTask.get());
         * 4.线程池：实际开发中的方式
         *        给线程池提交任务
         *        service.execute(new Runnable01());
         *      1.创建：
         *          1、ExecutorService service = Executors.newFixedThreadPool(10);
         *          2、
         * 区别：
         * 1，2不能得到返回值，3可以
         * 1，2，3都不能控制资源
         * 4可以控制资源，稳定
         */


        System.out.println("end...");
    }

    public static class Thread01 extends Thread {
        @Override
        public void run() {
            System.out.println("当前线程：" + Thread.currentThread().getId());
            int i = 10 / 2;
            System.out.println("运行结果：" + i);
        }
    }
    public static class Runnable01 implements Runnable {
        @Override
        public void run() {
            System.out.println("当前线程：" + Thread.currentThread().getId());
            int i = 10 / 2;
            System.out.println("运行结果：" + i);
        }
    }
    public static class Callable01 implements Callable<Integer> {
        @Override
        public Integer call() throws Exception {
            System.out.println("当前线程：" + Thread.currentThread().getId());
            int i = 10 / 2;
            System.out.println("运行结果：" + i);
            return i;
        }
    }


}
